﻿package mortal.game.view.pack.other
{
    import __AS3__.vec.*;
    import com.gengine.resource.*;
    import com.mui.controls.*;
    import com.mui.display.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.events.*;
    import mortal.component.window.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.item.*;
    import mortal.game.view.firstReCharge.*;
    import mortal.mvc.interfaces.*;

    public class FixGiftBagPackageWin extends BaseWindow
    {
        private var _itemData:ItemData;
        private var _bg:ScaleBitmap;
        private var _getGiftBtn:GLoadingButton;
        private var _rewardList:Vector.<EffectItem>;
        private const _startYSize:int = 212;
        private const _bgStartYSize:int = 181;
        private const _btnStartY:int = 172;
        private var _isLoadCompl:Boolean = false;
        private static var _instance:FixGiftBagPackageWin;

        public function FixGiftBagPackageWin(param1:ILayer = null)
        {
            this._rewardList = new Vector.<EffectItem>;
            if (_instance != null)
            {
                throw new Error(" FixGiftBagPackage 单例 ");
            }
            setSize(299, this._startYSize);
            this.title = Language.getString(35460);
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            LoaderHelp.addResCallBack(ResFileConst.GiftBagGetWin, this.onLoadCompl);
            return;
        }// end function

        private function onLoadCompl() : void
        {
            this._isLoadCompl = true;
            setSize(299, this._startYSize);
            this._bg = UIFactory.bg(4, 34, 297, this._bgStartYSize, this, "GiftBagGetWin_Bg");
            this._getGiftBtn = UIFactory.gLoadingButton(ResFileConst.GetGiftBtn2, 100, this._btnStartY, 114, 33, this);
            this._getGiftBtn.configEventListener(MouseEvent.CLICK, this.clickHandler);
            this._getGiftBtn.drawNow();
            if (this._itemData)
            {
                this.clearList();
                this.createReward();
            }
            return;
        }// end function

        private function clickHandler(event:MouseEvent) : void
        {
            if (event.target == this._getGiftBtn)
            {
                GameProxy.packProxy.useItem(this._itemData.serverData.uid, this._itemData.itemCode, 1);
                FixGiftBagPackageWin.instance.hide();
            }
            return;
        }// end function

        public function set itemData(param1:ItemData) : void
        {
            this._itemData = param1;
            if (this._isLoadCompl)
            {
                this.clearList();
                this.createReward();
            }
            return;
        }// end function

        private function createReward() : void
        {
            var _loc_3:Array = null;
            var _loc_4:ItemData = null;
            var _loc_14:EffectItem = null;
            var _loc_1:* = this._itemData.itemInfo as ItemGiftBagInfo;
            var _loc_2:* = _loc_1.itemList1.split("&");
            var _loc_5:* = _loc_2.length;
            var _loc_6:int = 0;
            while (_loc_6 < _loc_5)
            {
                
                if (_loc_2[_loc_6])
                {
                    _loc_3 = _loc_2[_loc_6].split("#");
                    _loc_4 = new ItemData(int(_loc_3[1]));
                    if (_loc_4.itemInfo && ItemsUtil.isFitCarrer(_loc_4))
                    {
                        _loc_14 = UICompomentPool.getUICompoment(EffectItem);
                        _loc_14.isDragAble = false;
                        _loc_14.isDropAble = false;
                        _loc_14.isShowLock = true;
                        _loc_14.isBind = Boolean(_loc_4.bind);
                        _loc_14.itemData = _loc_4;
                        _loc_14.amount = _loc_3[2];
                        this.addChild(_loc_14);
                        this._rewardList.push(_loc_14);
                    }
                }
                _loc_6++;
            }
            _loc_5 = this._rewardList.length;
            var _loc_7:int = 80;
            var _loc_8:int = 3;
            var _loc_9:* = _loc_5 < _loc_8 ? (_loc_5) : (_loc_8);
            var _loc_10:* = Math.ceil(_loc_5 / _loc_8);
            var _loc_11:* = (this.width - _loc_9 * _loc_7) * 0.5 + 8;
            var _loc_12:int = 86;
            _loc_6 = 0;
            while (_loc_6 < _loc_5)
            {
                
                this._rewardList[_loc_6].setItemStyle(ItemStyleConst.Big, ImagesConst.RewardItemBigBg, 4, 4);
                this._rewardList[_loc_6].x = _loc_6 % _loc_8 * _loc_7 + _loc_11;
                this._rewardList[_loc_6].y = int(_loc_6 / _loc_8) * _loc_7 + _loc_12;
                this._rewardList[_loc_6].showEffect(true, 30, 35, "ArriundEffect_zhi_big.swf");
                this._rewardList[_loc_6].updateColorShow();
                if (ItemsUtil.isPetEquip(this._rewardList[_loc_6].itemData) || ItemsUtil.isMountEquip(this._rewardList[_loc_6].itemData) || ItemsUtil.isFashionEquip(this._rewardList[_loc_6].itemData) || ItemsUtil.isWizardEquip(this._rewardList[_loc_6].itemData))
                {
                    this._rewardList[_loc_6].itemData.extInfo = new ItemExInfo();
                    this._rewardList[_loc_6].itemData.extInfo.strengthen = this._rewardList[_loc_6].itemData.itemInfo.itemLevel;
                    this._rewardList[_loc_6].itemData.extInfo.currentStrengthen = 0;
                    this._rewardList[_loc_6].updateStrengLevel();
                }
                _loc_6++;
            }
            var _loc_13:* = (_loc_10 - 1) * _loc_7;
            this.setSize(299, this._startYSize + _loc_13);
            this._bg.height = this._bgStartYSize + _loc_13;
            this._getGiftBtn.y = this._btnStartY + _loc_13;
            return;
        }// end function

        private function clearList() : void
        {
            var _loc_1:EffectItem = null;
            for each (_loc_1 in this._rewardList)
            {
                
                _loc_1.dispose(true);
            }
            this._rewardList.length = 0;
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._itemData = null;
            this._isLoadCompl = false;
            LoaderHelp.removeResEvent(ResFileConst.GiftBagGetWin, this.onLoadCompl);
            this._getGiftBtn.dispose(param1);
            this._bg.dispose(param1);
            this._getGiftBtn = null;
            this._bg = null;
            this.clearList();
            super.disposeImpl(param1);
            return;
        }// end function

        public static function get instance() : FixGiftBagPackageWin
        {
            if (!_instance)
            {
                _instance = new FixGiftBagPackageWin;
                _instance.layer = LayerManager.fullScreenTopLayer;
            }
            return _instance;
        }// end function

    }
}
